package com.pingao.mp.modular.sys.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import lombok.Data;

import java.time.LocalDateTime;

@Data
@TableName(value = "sys_log")
public class Log extends Model<Log> {
    //JsonSerialize解决数据传递到前端的时候其精度会丢失的问题，在序列化的时候把其序列化成字符串类型
    @JsonSerialize(using = ToStringSerializer.class)
    //ID_WORKER，采用mybatis-plus提供的雪花算法自动生成主键值
    @TableId(value = "id", type = IdType.ID_WORKER)
    private Long id;

    /**
     * 添加时间
     */
    @TableField(value = "create_time")
    private LocalDateTime createTime;

    /**
     * 请求方式
     */
    @TableField(value = "`method`")
    private String method;

    /**
     * 请求路径
     */
    @TableField(value = "servlet_path")
    private String servletPath;

    /**
     * 路径参数
     */
    @TableField(value = "query_string")
    private String queryString;

    /**
     * 访问主机
     */
    @TableField(value = "remote_host")
    private String remoteHost;

    /**
     * 主机地址
     */
    @TableField(value = "remote_addr")
    private String remoteAddr;

    /**
     * 表单数据
     */
    @TableField(value = "request_params")
    private String requestParams;

    /**
     * 用户ID
     */
    @TableField(value = "user_id")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long userId;
    /**
     * 用户名
     */
    @TableField(exist = false)
    private String userName;

    public static final String COL_ID = "id";

    public static final String COL_CREATE_TIME = "create_time";

    public static final String COL_METHOD = "method";

    public static final String COL_SERVLET_PATH = "servlet_path";

    public static final String COL_QUERY_STRING = "query_string";

    public static final String COL_REMOTE_HOST = "remote_host";

    public static final String COL_REMOTE_ADDR = "remote_addr";

    public static final String COL_REQUEST_PARAMS = "request_params";

    public static final String COL_USER_ID = "user_id";
}
